﻿using UnityEngine;
using System.Collections;

public class MainCar : MonoBehaviour {
	public GameObject explo;
	public GameObject mc;
    public Animator car_anim;

    public static Vector3 playPos;
	// Use this for initialization
	void Start () {
        car_anim = gameObject.GetComponent<Animator>();
        playPos = gameObject.transform.position;
	}
	
	// Update is called once per frame
	void Update () {
		if (Input.inputString == "s" || Input.inputString == "S") {
			this.transform.position = new Vector3(transform.position.x, -transform.position.y, transform.position.z);
		}
		if (Input.inputString == "w" || Input.inputString == "W") {
			this.transform.position = new Vector3(transform.position.x, -transform.position.y, transform.position.z);
		}
	}

    //public void StartExplotion()
    //{
    //    Vector3 explo_2 = new Vector3(0,0,0);
    //    Instantiate(explo, explo_2, Quaternion.identity);
    //    //explo.activeSelf(true);
    //    explo.SetActive(true);

    //}

    public void StartExplotion()
    {
        car_anim.SetBool("isCrashed", true);
        
        
    }

	void OnTriggerEnter2D(Collider2D collider) {		
		if (collider.gameObject.CompareTag ("Enemy")) {
			Debug.Log("Player was crash" + collider.name);
			GLOBAL.s_isGameOver = true;
			StartExplotion();
		}

        if (collider.gameObject.CompareTag("Coin"))
        {
            // Increase coin 
            GLOBAL.s_iGold += 1;

            // Destroy coin object

        }

        if (collider.gameObject.CompareTag("Fuel"))
        {
            // Increate fuel
            GLOBAL.s_iFuel += 1;

            // Destroy fuel object

        }

		
	}



   

    public GameObject getInstance()
    {
        return gameObject;
    }
	
}
